﻿//////////////////////////////////////////////////////////////////////////////
//
//  Copyright © 1998-2024 Glodon Company Limited.  All rights reserved.
//
//  Use of this software is subject to the terms of the Glodon license
//  agreement provided at the time of installation or download, or which
//  otherwise accompanies this software in either electronic or hard copy form.  
//
//////////////////////////////////////////////////////////////////////////////


#pragma once
#include "GnufInputControl.h"
#include "GnufBaseUtils.h"

namespace gnuf {
    class Info;
    typedef Range<int> SliderRange;
    
    class GNUF_BASE_EXPORT ISliderControlHandler
        : public IInputControlHandler
    {
    public:
        virtual void onValueChanged(const int) = 0;
        virtual void onRangeChanged(const std::pair<int, int> &) = 0;
    };
    
    class GNUF_BASE_EXPORT SliderControlAdpatation
        : public InputControlAdaptation
    {
    protected:
        SliderControlAdpatation();
        virtual ~SliderControlAdpatation();

        // Inherits from InputControlAdaptation...
        virtual void onVisibilityChanged(bool) override {}
        virtual void onSelectionChanged(bool) override {}

    public:
        virtual void onValueChanged(const int) = 0;
        virtual void onRangeChanged(const std::pair<int, int>&) = 0;
    };
    
    class GNUF_BASE_EXPORT SliderControl
        : public InputControl
    {
        CANNOT_COPY_OR_ASSIGN(SliderControl)
    public:
        static const EItemType Type;
        SliderControl(ISliderControlHandler* handler, bool readonly, const std::pair<int, int>& sliderRange, const std::wstring& unit, gcmp::OwnerPtr< Info > &info);
        virtual ~SliderControl();
        
        inline bool readonly() const { return m_readonly; }
        inline const Info * info() const { return m_info.get(); }
        inline const std::pair<int, int>& range() const { return m_range; }
        inline const std::wstring& unit() const { return m_unit; }

        void setValue(int, const SliderControlAdpatation * trigger = nullptr);
        void setRange(const std::pair<int, int>&, const SliderControlAdpatation* trigger = nullptr);

    private:
        bool m_readonly;

        std::pair<int, int> m_range;
        std::wstring m_unit;
        gcmp::OwnerPtr< Info > m_info;
    };
}
